package com.rongshu.sendmessage.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rongshu.sendmessage.R;
import com.rongshu.sendmessage.base.BaseActivity;
import com.rongshu.sendmessage.util.ToastUtils;
import com.rongshu.sendmessage.util.httpUtil.HYContent;

public class SexSelectActivity extends BaseActivity {

    private ImageView iv_nan_select,iv_nv_select;
    private int selectIndex=-1;
    private int sex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=this;
        setContentView(R.layout.activity_sex_select);
        initView();
    }

    private void initView() {
        TextView title=findViewById(R.id.title);
        LinearLayout titleLayLeft = findViewById(R.id.titleLayLeft);
        titleLayLeft.setOnClickListener(view->finish());
        title.setText("设置性别");
        iv_nan_select=findViewById(R.id.iv_nan_select);
        iv_nv_select=findViewById(R.id.iv_nv_select);
        selectIndex=getIntent().getExtras().getInt("sex");
        if (selectIndex==-1){
            iv_nv_select.setVisibility(View.GONE);
            iv_nan_select.setVisibility(View.GONE);
        }else if(selectIndex==0){
            iv_nv_select.setVisibility(View.GONE);
            iv_nan_select.setVisibility(View.VISIBLE);
        }else{
            iv_nv_select.setVisibility(View.GONE);
            iv_nan_select.setVisibility(View.VISIBLE);
        }
    }

    public void onClick(View view) {
        if (view.getId()==R.id.re_nan){
            iv_nv_select.setVisibility(View.GONE);
            iv_nan_select.setVisibility(View.VISIBLE);
            selectIndex=0;
        }else if(R.id.re_nv==view.getId()){
            iv_nv_select.setVisibility(View.VISIBLE);
            iv_nan_select.setVisibility(View.GONE);
            selectIndex=1;

        }else if(R.id.btn_confirm==view.getId()){
            if (selectIndex==-1){
                ToastUtils.show(mContext,"请选择后再提交哦");
                return;
            }
            Intent intent=new Intent();
            intent.putExtra("sex",selectIndex);
            setResult(HYContent.SUCCESS_CODE,intent);
            finish();
        }
    }
}